using System;
using CommonTypes.Client;
using Client.Model;
using System.Reflection;
using System.Collections;
using System.Threading;
using Client.Threads;

namespace Client.RemoteObjects
{
    public class ServerToClient: MarshalByRefObject, IServerToClient
    {

        private ClientData _clientData;

        public ServerToClient(ClientData clientData)
        {
             _clientData = clientData;
        }

        public void TicketGenerationAnswer(long ticketNumber, DateTime clientNonce)
        {
            Reservation reservation = _clientData.SetReservationTicket(clientNonce, ticketNumber);

            ReservationInitiatorThread reservationThreadObject = new ReservationInitiatorThread(_clientData, reservation);
            _clientData.AddReservationThread(reservationThreadObject);

            ThreadStart reservationThreadStart = new ThreadStart(reservationThreadObject.Run);
            Thread reservationThread = new Thread(reservationThreadStart);
            reservationThread.IsBackground = true;
            reservationThread.Start();

            reservationThreadObject.ReservationThread = reservationThread;
        }

        public override object InitializeLifetimeService()
        {
            return null;
        }
    }
}
